﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Active.Core;
using System.Collections.Generic;

public partial class Bill_OrderList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void aspnetPager_PageChanged(object sender, EventArgs e)
    {
        OrderListGridView.DataBind();
    }

    #region Business Methods

    private OrderList GetOrderList()
    {
        //清除Session中的业务对象, 避免出现Session保存错误的业务对象
        if (Session["CurrentObj"] != null)
        {
            Session["CurrentObj"] = null;
        }
        int year = 0;
        int month = 0;
        int pageNo = aspnetPager.CurrentPageIndex;
        int pageSize = aspnetPager.PageSize;
        int mediaId = 0;
        int.TryParse(Request.QueryString["mediaId"], out mediaId);

        List<int> regionIds = new List<int>();
        foreach (object key in Profile.ManagerRegions.Keys)
        {
            regionIds.Add(int.Parse(key.ToString()));
        }
        OrderList list = null;
        try
        {
            list = OrderList.GetOrderList(regionIds.ToArray(), mediaId, year, month, pageNo, pageSize);
            aspnetPager.RecordCount = list.TotalRecordsCount;
        }
        catch (System.Security.SecurityException)
        {
            Response.Redirect("~/");
        }
        return list;
    }

    #endregion

    #region OrderListDataSource

    protected void OrderListDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
    {
        e.BusinessObject = GetOrderList();
    }

    #endregion
    
}
